package com.company.thread;

/**
 * @description: some desc
 * @author: ruoan
 * @date: 2020/10/23 16:50
 */
public class Thread11 {
    final static Object o = new Object();
    final static Object o2 = new Object();
    public static class OtherRunnableObj3 implements Runnable {
        @Override
        public void run() {
            synchronized (o) {
                synchronized (o) {
                    try {
                        System.out.println(Thread.currentThread().getName() + "进入睡眠");
                        for (int i = 1; i < 100; i++) {
                            System.out.println("i:" + i);
                            Thread.sleep(5);
                        }
                    } catch (InterruptedException e) {
                        System.out.println(Thread.currentThread().getName() + "退出睡眠");
                        //e.printStackTrace();
                    }
                }
            }
        }
    }
    public static void main(String[] args) {
        Thread t = new Thread(new OtherRunnableObj3());

        t.start();
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //主线程获取对象o的互斥锁
        synchronized (o){
            System.out.println("主线程获取对象o的互斥锁");
        }


    }
}
